package oj_leetcode;

import java.util.*;

class LetterCombination {
    private static Map<Character, List<String>> map = new HashMap<>();
    static{
        map.put('2', Arrays.asList("a", "b", "c"));
        map.put('3', Arrays.asList("d", "e", "f"));
        map.put('4',Arrays.asList("g","h","i"));
        map.put('5',Arrays.asList("j","k","l"));
        map.put('6',Arrays.asList("m","n","o"));
        map.put('7',Arrays.asList("p","q","r","s"));
        map.put('8',Arrays.asList("t","u","v"));
        map.put('9',Arrays.asList("w","x","y","z"));
    }
    public List<String> letterCombinations(String digits) {
        if(digits.length() == 0){
            return Collections.emptyList();
        }
        if(digits.length() == 1){
            return map.get(digits.charAt(0));
        }else{
            List<String> left = letterCombinations(digits.substring(0,1));
            List<String> right = letterCombinations(digits.substring(1));
            List<String> res = new ArrayList<>();
            for(int i = 0; i< left.size();i++){
                for(int j = 0; j< right.size();j++){
                    res.add(left.get(i)+right.get(j));
                }
            }
            return res;
        }
    }
}